const path = require('path');
// html-webpack-plugin 1.将html页面也托管在内存中。2.将打包好的js文件bundle.js追加到body结束标签的前面
const htmlWebpackPlugin = require('html-webpack-plugin');
// clean-webpack-plugin 清除上次打包留下的文件夹
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
module.exports = {
	mode: 'development',
	entry: {
		app: './src/main.js',
	},
	output: {
		// 必须写成绝对路径
		path: path.resolve(__dirname, 'dist'),
		filename: 'bundle.js',
	},
	plugins: [
		new htmlWebpackPlugin({
			template: './src/index.html',
			filename: 'index.html',
		}),
		new htmlWebpackPlugin({
			template: './src/success.html',
			filename: 'success.html',
		}),
		new CleanWebpackPlugin(),
	],
	module: {
		rules: [
			{ test: /\.css$/, use: ['style-loader', 'css-loader'] },
			{ test: /\.scss|sass$/, use: ['style-loader', 'css-loader', 'sass-loader'] },
			{ test: /\.jsx?$/, use: 'babel-loader', exclude: /node_modules/ },
		],
	},
};
